/**
    @file pixelmail.cpp
    @brief Mailbox for messaging between game objects
*/
#include "pixel/pixelmail.hpp"

template<> pm3::PIXELMAIL* Ogre::Singleton<pm3::PIXELMAIL>::ms_Singleton = 0;
pm3::PIXELMAIL pm3::g_mail;

pm3::PIXELPOST::PIXELPOST( const std::string &s_type ) {
    m_type = s_type;
}

pm3::PIXELPOST::~PIXELPOST() {
    // Just chill
}

pm3::PIXELMAIL::PIXELMAIL() {
    // Just chill
}

pm3::PIXELMAIL::~PIXELMAIL() {
    clean();
}

pm3::PIXELPOST& pm3::PIXELPOST::operator=( const PIXELPOST &r_post ) {
    m_type = r_post.m_type;
    return *this;
}

void pm3::PIXELMAIL::post( const pm3::PIXELPOST &r_post ) {
    m_posts.push_back( r_post );
}

pm3::PIXELPOST pm3::PIXELMAIL::take() {
    //! \todo The mailsystem should be redesigned - should support directed posts with callbacks

    // Return a dummy when there are no more posts
    if (m_posts.empty())
        return PIXELPOST();

    pm3::PIXELPOST post = m_posts.front();
    m_posts.pop_front();

    return post;
}

void pm3::PIXELMAIL::clean() {
    m_posts.clear();
}
